package com.example.skindemo.loader;

import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;

import java.io.File;

import skin.support.utils.SkinConstants;

/**
 * 重新定义的sd卡的路径
 */

public class CustomSkinFileUtils {
    public static String getSkinDir(Context context) {
        File skinDir = new File(getExternalStorageDirectory(context),
                SkinConstants.SKIN_DEPLOY_PATH);
        if (!skinDir.exists()) {
            skinDir.mkdirs();
        }
        return skinDir.getAbsolutePath();
    }

    private static String getExternalStorageDirectory(Context context) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            File cacheDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath());

            if (cacheDir != null && (cacheDir.exists() || cacheDir.mkdirs())) {
                return cacheDir.getAbsolutePath();
            }
        }

        return context.getExternalCacheDir().getAbsolutePath();
    }


    public static boolean isFileExists(String path) {
        return !TextUtils.isEmpty(path) && new File(path).exists();
    }
}
